package org.embedchat.database;

import org.embedchat.database.dao.ChatRoomDAOImpl;
import org.embedchat.database.dao.HibernateUtil;
import org.embedchat.database.dao.UserDAOImpl;

public class DAOFactoryInterfaceImpl implements DAOFactoryInterface {

	/**
	 * Used for database initialization (is this not done)
	 *
	 */
	public DAOFactoryInterfaceImpl() {
		HibernateUtil.getSessionAndBeginTransaction();
		HibernateUtil.commitTransaction();
	}
	
	public UserDAOInterface getUserDAO() {
		return (UserDAOInterface) new UserDAOImpl().setSession(HibernateUtil.getSessionAndBeginTransaction());
	}

	public ChatRoomDAOInterface getChatRoomDAO() {
		return (ChatRoomDAOInterface) new ChatRoomDAOImpl().setSession(HibernateUtil.getSessionAndBeginTransaction());
	}
	
	public void freeDAO(Object daoObject) {
		HibernateUtil.commitTransaction();
	}
}
